<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <link href="../../style/css/style.css" rel="stylesheet" type="text/css" />
    <script src="../../style/js/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            //自动向servlet发送请求
            $.get("../../role/Role",function (res){
                if (res==201){
                    window.parent.location.replace("../login.html");
                }else if (res==500){
                    alert("服务器忙碌list");
                }else {
                    var str1=" ";
                    for (i=0;i<res.data.length;i++){
                        str1+= "<tr align='center'>";
                        str1+="<td>"+(i+1)+"</td>";
                        str1+="<td>"+res.data[i].name+"</td>";
                        str1+="<td>"+res.data[i].describ+"</td>"
                        str1+="<td>"+res.data[i].admin.account+"</td>"
                        str1+="<td>"+(new  Date(res.data[i].operateTime).toLocaleString())+"</td>"
                        str1+="<td><a href='javaScript:void(0)' onclick='updateId("+res.data[i].id+")'>修改</a>"+
                            "<a href='javaScript:void(0)' onclick='del("+res.data[i].id+")'>删除</a></td>";
                        str1+="</tr>";
                    }
                    $("#tableId").append(str1);
                }
                console.log(res);
            },"json");
        });
        //删除角色
        function del(id){
            alert(id);
            if (confirm("您确定删除吗")){
                $.get("../../role/delete",{id:id},function (res) {
                    if (res.code==201){
                        alert("删除成功");
                        location.reload();
                    }else if (res.code==200){
                        alert("删除失败");
                        location.replace("../login.html");
                    }
                    else {
                        alert("服务器忙!!");
                    }
                });
            }
        }

        //修改角色
        function updateId(id) {
            location.assign("update.html?id="+id);
        }
    </script>
</head>


<body>
<div class="rightinfo">
    <!-- 顶部按钮 -->
    <div class="tools">
        <ul class="toolbar">
            <a href="add.html">
                <li class="click">
                    <span><img src="../../style/img/adminMainPicture/t01.png" /></span>
                    添加
                </li>
            </a>
        </ul>
    </div>
    <!--数据列表 -->
    <form >
        <table class="tablelist" id="tableId">
            <th>编号<i class="sort"><img src="../../style/img/adminMainPicture/px.gif" /></i></th>
            <th>名称</th>
            <th>描述</th>
            <th>操作人</th>
            <th>操作时间</th>
            <th>其他操作</th>

        </table>
    </form>
</div>
</body>
</html>
